package com.jh.concurrent.base.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title InterruptDemo.java
 * @package com.jh.concurrent.base.interrupt
 * @description interrupt示例
 * @date 2019-05-09 16:51
 */
public class InterruptDemo {

    public static int i;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                i++;
            }
            System.out.println("i：" + i);
        }, "Thread1");

        thread.start();
        TimeUnit.SECONDS.sleep(1);
        // 通知子线程中断任务
        thread.interrupt();
    }

}
